package com.aaa.sys.controller;

import com.aaa.common.util.Result;
import com.aaa.common.util.ResultStatus;
import com.aaa.common.entity.OperLog;
import com.aaa.sys.service.OperLogService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 操作日志记录(OperLog)表控制层
 *
 * @author yuxiujie
 * @since 2021-01-21 09:33:51
 */
@RestController
@RequestMapping("operLog")
@ApiOperation("operLog控制器")
public class OperLogController {
    /**
     * 服务对象
     */
    @Resource
    private OperLogService operLogService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ApiOperation("单个对象查询")
    public Result<OperLog> selectOne(Integer id) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.operLogService.queryById(id));
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @return 对象列表
     */
    @PostMapping("queryAll")
    public Result<PageInfo<OperLog>> queryAll(Integer pageNo, Integer pageSize, @RequestBody OperLog operLog) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.operLogService.queryAll(pageNo, pageSize, operLog));
    }

    /**
     * 新增数据
     *
     * @param operLog 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result<OperLog> insert(@RequestBody OperLog operLog) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.operLogService.insert(operLog));
    }

    /**
     * 修改数据
     *
     * @param operLog 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result<OperLog> update(@RequestBody OperLog operLog) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.operLogService.update(operLog));
    }

    /**
     * 通过主键删除数据
     *
     * @param operLogId 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    public Result<Boolean> deleteById(Integer operLogId) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.operLogService.deleteById(operLogId));
    }
}